#include "Order.h"

/**
 * Initializes the orderArray and scrambles the array
 * The lowest number is 0 the highest numbers is numFactors - 1
 * @param the max number of factors
 */
Order::Order (int numFactors) {
  size = numFactors; // save the number of factors in the structure
  std::vector<int>::iterator it; // use the iterator to initialize the vector
  for (int i=0; i<numFactors; i++) {
    orderArray.push_back (i); // initialize the vector to 1-numFactors in order
  }

  srand((unsigned)time(0)); // generate random number seed
  int random_integer = rand() % NUM_TIMES_TO_SHUFFLE_INITIAL_ORDER + 1; // generate random number
  for (int i=0; i< random_integer; i++) { // shuffle the ordering this many times, each time the program runs it should be shuffled a different amount of times
    std::random_shuffle(orderArray.begin(), orderArray.end()); // scramble the initial vector, this way each time the program is run it will start off with a different ordering
  }
}

/**
 * Scrambles the orderArray using random_shuffle()
 * http://www.cplusplus.com/reference/algorithm/random_shuffle/
 * This is O(n)
 */
void Order::rescramble () {
  std::random_shuffle(orderArray.begin(), orderArray.end());
}

/**
 * Print the orderArray
 */
void Order::print () {
  std::cout <<"Order: ";
  for (int i=0; i<size; i++) {
    std::cout << orderArray[i] << " ";
  }
  std::cout << std::endl;
}
